<?php
	header("Content-Type: text/html; charset=utf-8");
	require_once(dirname(__FILE__) . '/' . 'SQLOperation.class.php');
	
	$db = new SQLOperation("localhost", "test");
	if ($db->connect()) {
		if (!empty($_POST['account']) && !empty($_POST['psw'])) {
			$timestamp = $_POST['timestamp'];
			$cid = $_POST['cid'];
			$type = $_POST['type'];
			settype($type, "integer");
			$result = $db->insert($type == 0 ? "register" : "server", 
					array("account", "password", "cid", "timestamp"), 
					array($_POST['account'], $_POST['psw'], $cid, $timestamp));
			if ($result) {
				$arr = array("code"=>0, "msg"=>"success");
				echo json_encode($arr);
			} else {
				$arr = array("code"=>100, "msg"=>mysql_errno());
				echo json_encode($arr);
			}			
		}
		
		$db->close();
	} else {
		$arr = array("code"=>100, "msg"=>mysql_errno());
		echo json_encode($arr);
	}
?>